package com.ng.servive.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ng.common.service.CacheServiceImpl;
import com.ng.common.utils.PageUtils;
import com.ng.common.utils.Query;
import com.ng.dao.CjfxBaseDao;
import com.ng.entity.CJFXBASEINFO;
import com.ng.servive.CjfxBaseService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author cb
 * @Description TODO
 * @date 2023/3/9
 */

@Service
public class CjfxBaseServiceImpl  extends ServiceImpl<CjfxBaseDao,CJFXBASEINFO>   implements CjfxBaseService {
        @Override
    public PageUtils queryPage(CJFXBASEINFO entity, PageUtils page) {


      //  PageUtils  bb=new PageUtils();
        String bookname = entity.getTitle();
        String sponsorOne=entity.getSponsorOne();
        String  pyszm=entity.getPyszm();
        String fxcode=entity.getFxcode();
        List<String> syscode=entity.getSyscodes();

            QueryWrapper<CJFXBASEINFO> queryWrapper=new QueryWrapper<CJFXBASEINFO>();
            if(syscode!=null&&syscode.size()>0){
                queryWrapper.and(wrapper->{
                    for (String item:syscode ) {
                        wrapper.or().like("期刊标识码",item);
                    }
                });
            }
            //  queryWrapper.like("classcode",1);
            queryWrapper.like(StringUtils.isNotBlank(bookname),"c_name", bookname)
                    .like(StringUtils.isNotBlank(sponsorOne),"主办单位1", sponsorOne)
                    .eq(StringUtils.isNotBlank(pyszm)&&pyszm.equals("全部")==false,"PY_203",pyszm);
            IPage<CJFXBASEINFO> ipage = this.page(new Query<CJFXBASEINFO>(page).getPage(),queryWrapper);
            System.out.println(ipage);
            return new PageUtils(ipage);

       // return  bb;
    }

    @Override
    public CJFXBASEINFO findone(CJFXBASEINFO entity) {
        String pykm=entity.getPinyinName();
        CJFXBASEINFO result=new CJFXBASEINFO();
        QueryWrapper<CJFXBASEINFO>queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("PYKM",pykm);
        result=  this.baseMapper.selectOne(queryWrapper);
         return result;
    }
}
